<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="数据日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dataDt">
              <j-date placeholder="请选择数据日期" v-model="model.dataDt"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="担保合同金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dbhtje">
              <a-input-number v-model="model.dbhtje" placeholder="请输入担保合同金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="担保合同金额折人民币" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dbhezrmb">
              <a-input-number v-model="model.dbhezrmb" placeholder="请输入担保合同金额折人民币" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="抵质押率" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dzyl">
              <a-input-number v-model="model.dzyl" placeholder="请输入抵质押率" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="担保人证件类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zjlx">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择担保人证件类型"
                v-model="model.zjlx"
                dict="llbb_param_config,name,code"
                pidValue="2eb99a6c4d204f998cbb2781620be14d"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="担保人证件代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zjhm">
              <a-input v-model="model.zjhm" placeholder="请输入担保人证件代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="担保人国民经济部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="gmjjbm">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择担保人国民经济部门"
                v-model="model.gmjjbm"
                dict="llbb_param_config,name,code"
                pidValue="1382949237084336130"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="担保人行业" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dbrhy">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择担保人行业"
                v-model="model.dbrhy"
                dict="jrsj_hyfl_config,name,code"
                pidValue="1"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="担保人地区代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dbrdqdm">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择担保人地区代码"
                v-model="model.dbrdqdm"
                dict="jrsj_xzqhdm_config,name,code"
                pidValue="1"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="担保人企业规模" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dbrqygm">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择担保人企业规模"
                v-model="model.dbrqygm"
                dict="llbb_param_config,name,code"
                pidValue="197a02d9852d4faa9c69fdc93d6a0943"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="金融机构代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jrjgdm">
              <a-input v-model="model.jrjgdm" placeholder="请输入金融机构代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="内部机构号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="nbjgh">
              <a-input v-model="model.nbjgh" placeholder="请输入内部机构号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="担保合同编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dbhtbm">
              <a-input v-model="model.dbhtbm" placeholder="请输入担保合同编码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="被担保合同编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bdbhtbm">
              <a-input v-model="model.bdbhtbm" placeholder="请输入被担保合同编码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="担保合同类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dbhtlx">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择担保合同类型"
                v-model="model.dbhtlx"
                dict="llbb_param_config,name,code"
                pidValue="650b2a28fda14b088f9eef46f1b28709"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="交易类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jylx">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择交易类型"
                v-model="model.jylx"
                dict="llbb_param_config,name,code"
                pidValue="c4368892b55c4b53979061648341ec4f"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="担保合同起始日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dbqsrq">
              <j-date placeholder="请选择担保合同起始日期" v-model="model.dbqsrq"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="担保合同到期日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dbdqrq">
              <j-date placeholder="请选择担保合同到期日期" v-model="model.dbdqrq"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="币种" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bz">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择币种"
                v-model="model.bz"
                dict="jrsj_bz_config,name,code"
                pidValue="1382973175608823809"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'JsCdLoanGuarContInfoForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 7 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/jsCdLoanGuarContInfo/jsCdLoanGuarContInfo/add",
          edit: "/jsCdLoanGuarContInfo/jsCdLoanGuarContInfo/edit",
          queryById: "/jsCdLoanGuarContInfo/jsCdLoanGuarContInfo/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.guid){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }

        })
      },
    }
  }
</script>
